package site.marqstree.kotlin.library.good.ui.activity.detail.tabs

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.alibaba.android.arouter.launcher.ARouter
import site.marqstree.kotlin.library.good.ui.activity.detail.tabs.tabinfor.FragGoodInfo
import site.marqstree.kotlin.library.good.ui.bean.GoodDetailBean
import site.marqstree.kotlin.library.good.ui.bean.TabBean


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.good.ui.activity.detail
 * 文件名: TabsAdapter
 * 创建者: marqstree
 * 创建时间: 2020/3/14 16:15
 * 描述: TODO
 */
class TabsAdapter(frgmentActivity: FragmentActivity,
                val mGoodDetailBean: GoodDetailBean)
            : FragmentStateAdapter(frgmentActivity) {
    override fun getItemCount(): Int {
        // 返回集合的长度，Fragment的数量就是根据这个集合来创建的
        return mGoodDetailBean.tabs.size
    }

    override fun createFragment(position: Int): Fragment {
        // 实例化Fragment
        if(mGoodDetailBean.tabs[position].name=="商品详情"){
            return ARouter.getInstance()
                .build("/good/fragment/goodinfo")
                .withObject("mImages", mGoodDetailBean.tabs[position].pictures)
                .withObject("mGoodDetailBean", mGoodDetailBean)
                .navigation() as Fragment
        } else {
            return ARouter.getInstance()
                .build("/good/fragment/goodspec")
                .withObject("mImages", mGoodDetailBean.tabs[position].pictures)
                .navigation() as Fragment
        }
    }
}